/*
  ******************************************************************************
  * @file    driver_display.c
  * @author  FreqChip Firmware Team
  * @version V1.0.0
  * @date    2022
  * @brief   display abstract interfase.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 FreqChip.
  * All rights reserved.
  ******************************************************************************
*/

#include <stdint.h>
#include "app_lvgl.h"
#include "app_config.h"


#include "driver_display_dev.h"

#ifdef DISPLAY_TYPE_GC9C01
#include "driver_gc9c01.h"
#endif
#ifdef DISPLAY_TYPE_JD9854
#include "driver_jd9854.h"
#endif
#ifdef DISPLAY_TYPE_SH8601A
#include "driver_sh8601a.h"
#endif
#ifdef DISPLAY_TYPE_ICNA3310
#include "driver_icna3310.h"
#endif
#ifdef DISPLAY_TYPE_SH8601Z
#include "driver_sh8601z.h"
#endif

#ifdef DISPLAY_TYPE_NV3047_RGB
#include "driver_nv3047_rgb.h"
#endif

#ifdef DISPLAY_TYPE_ST7701_RGB
#include "driver_st7701_rgb.h"
#endif

#ifdef DISPLAY_TYPE_ST2568_RGB
#include "driver_st2568_rgb.h"
#endif

#ifdef DISPLAY_TYPE_NV3041A
#include "driver_nv3041a.h"
#endif

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
#include "driver_st7282_rgb_hw.h"
#endif

extern void* get_display_buffer1(void);

void display_dev_init(void)
{
#ifdef DISPLAY_TYPE_GC9C01
    gc9c01_init();
#endif
#ifdef DISPLAY_TYPE_JD9854
    jd9854_init();
#endif
#ifdef DISPLAY_TYPE_SH8601A
    sh8601a_init();
#endif
#ifdef DISPLAY_TYPE_ICNA3310
    icna3310_init();
#endif
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_init();
#endif
#ifdef DISPLAY_TYPE_NV3047_RGB
	 extern void rgb_display_controller_init(void);
	 rgb_display_controller_init();
     rgb_display_init(get_display_buffer1());
#endif
#ifdef DISPLAY_TYPE_ST7701_RGB
	st7701_init(get_display_buffer1());
#endif

#ifdef DISPLAY_TYPE_ST2568_RGB
	//st2568_init(get_display_buffer1());
#endif

#ifdef DISPLAY_TYPE_NV3041A
    nv3041a_init();
#endif

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
	st7282_init(get_display_buffer1());
#endif

}

void display_set_window(uint16_t x_s, uint16_t x_e, uint16_t y_s, uint16_t y_e)
{
#ifdef DISPLAY_TYPE_GC9C01
    gc9c01_set_window(x_s, x_e, y_s, y_e);
#endif
#ifdef DISPLAY_TYPE_JD9854
    jd9854_set_window(x_s, x_e, y_s, y_e);
#endif
#ifdef DISPLAY_TYPE_SH8601A
    sh8601a_set_window(x_s, x_e, y_s, y_e);
#endif
#ifdef DISPLAY_TYPE_ICNA3310
    icna3310_set_window(x_s, x_e, y_s, y_e);
#endif
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_set_window(x_s, x_e, y_s, y_e);
#endif
#ifdef DISPLAY_TYPE_NV3041A
	nv3041a_set_window(x_s, x_e, y_s, y_e);
#endif	
}

void display_update(uint32_t pixel_count, uint8_t pixel_width, void *data)
{
#ifdef DISPLAY_TYPE_GC9C01
    gc9c01_display(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_JD9854
    jd9854_display(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_SH8601A
    sh8601a_display(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_ICNA3310
    icna3310_display(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_display(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_NV3041A
	nv3041a_display(pixel_count, pixel_width, data);
#endif	

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
#endif

}

void display_update_dma(uint32_t pixel_count, uint8_t pixel_width, void *data)
{
#ifdef DISPLAY_TYPE_GC9C01
    gc9c01_display_dma(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_JD9854
    jd9854_display_dma(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_SH8601A
    sh8601a_display_dma(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_ICNA3310
    icna3310_display_dma(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_display_dma(pixel_count, pixel_width, data);
#endif
#ifdef DISPLAY_TYPE_NV3047_RGB
	   	
#endif	

#ifdef DISPLAY_TYPE_ST7701_RGB

#endif

#ifdef DISPLAY_TYPE_ST2568_RGB

#endif

#ifdef DISPLAY_TYPE_NV3041A
	nv3041a_display_dma(pixel_count, pixel_width, data);
#endif

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
#endif

}

void display_power_off(void)
{
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_power_off();
#endif

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
    st7282_power_off();
#endif

}

void display_power_on(void)
{
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_power_on();
#endif

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
    st7282_power_on();
#endif
}

__RAM_CODE void display_update_dma_isr(void)
{
#ifdef DISPLAY_TYPE_GC9C01
    gc9c01_display_dma_isr();
#endif
#ifdef DISPLAY_TYPE_JD9854
    jd9854_display_dma_isr();
#endif
#ifdef DISPLAY_TYPE_SH8601A
    sh8601a_display_dma_isr();
#endif
#ifdef DISPLAY_TYPE_ICNA3310
    icna3310_display_dma_isr();
#endif
#ifdef DISPLAY_TYPE_SH8601Z
    sh8601z_display_dma_isr();
#endif
	
#ifdef DISPLAY_TYPE_ST7701_RGB
	st7701_rgb_display_dma_irq();
#endif	

#ifdef DISPLAY_TYPE_ST2568_RGB
	//st2568_rgb_display_dma_irq();
#endif	

#ifdef DISPLAY_TYPE_NV3041A
	nv3041a_display_dma_isr();
#endif	

#ifdef DISPLAY_TYPE_ST7282_RGB_HW
    st7282_rgb_display_dma_irq();
#endif
}
